package com.aisb.manage;

import com.github.pagehelper.Page;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class NoticeService {
    private static Logger logger = LoggerFactory.getLogger(NoticeService.class);

    @Autowired
    NoticeDao noticeDao;

    public Object noticeOne(String noticeId) {
        return noticeDao.queryOne(noticeId);
    }

    public Object noticeOne(Map param) {
        return noticeDao.queryOne(param);
    }

    public List noticeList(Map param) {
        List<Map> noticeList = noticeDao.queryList(param);

        return noticeList;
    }

    public Page noticeList(Map param, Integer pageNum, Integer pageSize) {
        if (null == pageNum) {
            pageNum = 1;
        }
        if (null == pageSize) {
            pageSize = 999999;
        }

        return noticeDao.searchPage(param, pageNum, pageSize);
    }

    public int noticeAdd(Map param) {
        return noticeDao.insert(param);
    }

    public int noticeModify(Map param) {
        return noticeDao.update(param);
    }

    @Transactional
    public int noticeModify(Set<String> noticeIds, Map modifyInfo) {
        try {
            for (String noticeId : noticeIds) {
                if (StringUtils.isBlank(noticeId)) {
                    continue;
                }
                modifyInfo.put("noticeId", noticeId);
                noticeDao.update(modifyInfo);
            }
        } catch (Exception e) {
            logger.error("{}", e);
            return 0;
        }

        return 1;
    }

    public int noticeDelete(Map param) {
        return noticeDao.delete(param);
    }
}
